package com.example.zuoye.dao;

import com.example.zuoye.entity.Liked;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface GoodsLikeDAO {
    /**
     * 关注
     * @param like
     * @return
     */
    @Insert("insert into good_like (obj_id,user_id,like_status) values(#{objId},#{userId},#{likeStatus})")
    boolean addLiked(Liked like);


    /**
     * 关注或取消关注
     * @param liked
     * @return
     */
    @Update("update good_like set like_status = #{likeStatus} where user_id = #{userId} and obj_id = #{objId}")
    boolean upadateLiked(Liked liked);

//    /**
//     * 查询单个用户的所有关注信息
//     * @param userId
//     * @return
//     */
//    @Select("select * from good_like where user_id = #{userId}")
//    List<Liked> getListLiked(String userId);


    /**
     * 查询单个用户的所有关注信息
     * @param userId
     * @return
     */
//    @Select("select good_name,good_price,good_introduce,good_date,good_number,good_image,good.good_id from good_like inner join good on good_like.obj_id = good.good_id where user_id=#{user_id})
    List<Liked> getListLiked(String userId);

    /**
     * 检测用户是否关注了
     * @param liked
     * @return
     */
    @Select("select * from good_like where user_id = #{userId} and obj_id = #{objId}")
    Liked checkedLike(Liked liked);

    /**
     * 更新关注表格
     * @param liked
     * @return
     */
    @Update("update good_like set like_status = #{likeStatus} where obj_id = #{objId} and user_id = #{userId}")
    boolean updateGoodLike(Liked liked);
}
